package com.atkxp.controller;

import com.atkxp.pojo.Comment;
import com.atkxp.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author user
 * @declaration
 * @create 2022/11/18-17:02
 */
@Controller
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    @Qualifier("commentServiceImpl")
    private CommentService commentService;


    @ResponseBody
    @RequestMapping("/addCommentLike")
    public int addLikes(int id){
        return commentService.addLike(id);
    }

    @ResponseBody
    @RequestMapping("/deleteCommentLike")
    public int deleteLikes(int id){
        return commentService.deleteLike(id);
    }

    @RequestMapping("/writeComment")
    public String writeComment(Comment comment, HttpServletRequest request){
        comment.setCommentDate(new Date());
        commentService.writeComment(comment);
        return "redirect://blog/showBlog?id=" + comment.getBlogId();
    }

    @ResponseBody
    @RequestMapping("/deleteComment")
    public int deleteComment(int id){
        return commentService.deleteCommentById(id);
    }
}
